<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>统计字数</title>
    <style>
         .box{
            width: 500px;
            display: flex;
        }
        textarea{
            width: 300px;
            height: 50px;
            transition: all 0.7s;
        }
        textarea:focus{
            height: 100px;
        }
        img{
            width: 50px;
            height: 50px;
            border-radius: 25px;

        }
        button{
            background-color: blue;
        }
        span{
            margin-left: 400px;
            opacity: 0;
            transition: all 0.7s;
        }
        .list {
            min-width: 400px;
            max-width: 800px;
            display: flex;
        }
        .list .item {
            width: 100%;
            display: flex;
        }
        .list .item .info {
            flex: 1;
            border-bottom: 1px dashed #e4e4e4;
            padding-bottom: 10px;
        }
        .list .item p {
            margin: 0;
        }
        .list .item .name {
            color: #FB7299;
            font-size: 14px;
            font-weight: bold;
        }
        .list .item .text {
            color: #333;
            padding: 10px 0;
        }
        .list .item .time {
            color: #999;
            font-size: 12px;
        }
    </style>
</head>

<body>
    <div class="box">
        <img src="/study-js/作业/王者荣耀/images/1.webp" alt="">
        <textarea name="" id="" placeholder="发一条友善的评论" maxlength="200" ></textarea>
        <button >发布</button>
    </div>
    <span>0/200字</span>
   <div class="list">
    <div class="item" style="display: none;">
      <i class="avatar"></i>
      <div class="info">
        <p class="name">清风徐来</p>
        <p class="text">大家都辛苦啦，感谢各位大大的努力，能圆满完成真是太好了[笑哭][支持]</p>
        <p class="time">2022-10-10 20:29:21</p>
      </div>
    </div>
  </div>
    <script>
        const tx = document.querySelector('textarea')
        const span = document.querySelector('span')
        const item = document.querySelector('.item')
        const text = document.querySelector('.text')
        tx.addEventListener('input',function(){
            span.innerHTML =`${tx.value.length + '/200字'}`
        })
        tx.addEventListener('focus',function(){
            span.style.opacity=1

        })
        tx.addEventListener('blur',function(){
            span.style.opacity=0
        })
         tx.addEventListener('keyup',function(e){
        if(e.key ==='Enter'){
            if(tx.value.trim()!==''){       
                item.style.display='block'
                text.innerHTML=tx.value
            }
            tx.value=''
            span.innerHTML='0/200字'
        }
    })
    </script>
</body>

</html>